package datamining.code.processtable;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class ProcessNameType {
	public static void main(String[] args) {
		String linha = null; //tupla inteira
		String dados[]; //array de atributos da tupla
		try {
			
			File input = new File("csvtables/beforeprocessing/name_type.csv");
			FileReader fileReader = new FileReader(input);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			
			File output = new File("csvtables/afterprocessing/name_type.csv");
			FileWriter fileWriter = new FileWriter(output);
			BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
			
			int cont=0;
			Vector<String> nomes = new Vector<String>();
			Vector<String> tipos = new Vector<String>();
			while((linha=bufferedReader.readLine())!=null) {
				dados=linha.split(";");
				if(!nomes.contains(dados[0].trim())) {
						nomes.add(dados[0].trim());
						tipos.add(dados[1].trim());
				}				
			}
			for (int i = 0; i < nomes.size(); i++) {
				bufferedWriter.write(i+1+";"+nomes.get(i)+";"+tipos.get(i)+"\n");
			}
			
			
			bufferedWriter.flush();
			bufferedWriter.close();
			
			System.out.println("Total de nomes diferentes encontrados: "+cont);
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}


	}

}
